package com.soft.bams.entity;

import com.soft.bams.exception.BalanceNotEnoughException;

import java.io.Serializable;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/17
 */
// 储蓄账户
public class SavingAccount extends Account{
    public SavingAccount() {
        super();
    }

    public SavingAccount(Long id, String password, String name, String personId, String email, double balance) {
        super(id, password, name, personId, email, balance);
    }

    @Override
    public Account withdraw(double amount) throws BalanceNotEnoughException {
        if (getBalance() < amount) {
            throw new BalanceNotEnoughException("您的银行卡余额不足！");
            /*System.out.println("您的银行卡余额不足！");
            return this;*/
        }
        setBalance(getBalance() - amount);
        return this;
    }

    @Override
    public String toString() {
        return "SavingAccount{" +
                "id=" + getId() +
                ", password='" + getPassword() + '\'' +
                ", name='" + getName() + '\'' +
                ", personId='" + getPersonId() + '\'' +
                ", email='" + getEmail() + '\'' +
                ", balance=" + getBalance() +
                '}';
    }
}
